﻿using UnityEngine;
using System.Collections;
using UnityEditor;
using System;

namespace Hont.HyperWigglePackage.Editor
{
    public class RestoreKeyframe : BaseWigglePlugins
    {
        PRPair[] mStorePRPairArray;


        protected override void OnExit()
        {
        }

        protected override void OnGUI()
        {
            if (GUILayout.Button("Store"))
            {
                mStorePRPairArray = new PRPair[mCore.FrameData.Length];
                mCore.FrameData.CopyTo(mStorePRPairArray, 0);
            }

            if (GUILayout.Button("Restore"))
            {
                mStorePRPairArray.CopyTo(mCore.FrameData, 0);

                mCore.UpdatePreview();
                mCore.UpdateTimeline();
            }

            if (GUILayout.Button("Remap"))
            {
                for (int i = 0; i < mCore.FrameData.Length; i++)
                {
                    var rate = i / (float)mCore.FrameData.Length;
                    var newIndex = Mathf.FloorToInt(rate * mStorePRPairArray.Length);
                    var item = mStorePRPairArray[newIndex];

                    mCore.FrameData[i] = item;
                }

                mCore.UpdatePreview();
                mCore.UpdateTimeline();
            }
        }
    }
}